package br.edu.unifei.cct720.trabalho05.principal.gui;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.border.TitledBorder;

import br.edu.unifei.cct720.trabalho05.gui.componentes.JButtonDesenhar;
import br.edu.unifei.cct720.trabalho05.gui.componentes.JButtonLimpar;
import br.edu.unifei.cct720.trabalho05.gui.componentes.JButtonSair;
import br.edu.unifei.cct720.trabalho05.gui.componentes.JButtonSobre;
import br.edu.unifei.cct720.trabalho05.gui.painel.PainelDesenho;
import br.edu.unifei.cct720.trabalho05.gui.painel.PainelSombreamento;
import br.edu.unifei.cct720.trabalho05.principal.controlador.ControladorPrincipal;
import br.edu.unifei.cct720.trabalho05.utils.constantes.Constantes;

/**
 * Classe responsavel por instanciar a interface principal
 * do projeto
 * 
 * @author fknappe
 */
public class JanelaPrincipal extends javax.swing.JFrame {

	// Declaracao das variaveis de instancia
	private ControladorPrincipal med;

	/**
	 * Construtor 
	 * 
	 * @param String title
	 */
	public JanelaPrincipal(String title) {
		super(title);
		this.med = new ControladorPrincipal(this);
		this.initComponents();
		this.med.registraEventos();
	}

	/**
	 * Metodo responsavel pela inicializacao e disposicao
	 * dos componentes na GUI
	 * 
	 * @return void
	 */
	public void initComponents() {
		java.awt.GridBagConstraints gridBagConstraints;

		// Inicializacao dos componentes
		panelMenuSuperior = new javax.swing.JPanel();
		panelMenuInferior = new javax.swing.JPanel();
		panelDesenho = new PainelDesenho();
		panelMenuSombreamento = new PainelSombreamento();
		btnDesenhar = new JButtonDesenhar("Desenhar", this.med);
		btnLimpar = new JButtonLimpar("Limpar", this.med);
		btnSobre = new JButtonSobre("Sobre...", this.med);
		btnSair = new JButtonSair("Sair...", this.med);
		panelMenuInferior = new javax.swing.JPanel();
		cmbFormas = new javax.swing.JComboBox(Constantes.FORMAS);
		
		// Definindo o content que sera utilizado na janela
		getContentPane().setLayout(new java.awt.GridBagLayout());
		
		cmbFormas.setSelectedIndex(-1);
		panelMenuSuperior.add(cmbFormas);
		
		btnDesenhar.setEnabled(false);
		panelMenuSuperior.add(btnDesenhar);
		
		btnLimpar.setEnabled(false);
		panelMenuSuperior.add(btnLimpar);
		
		panelMenuSuperior.setBorder(BorderFactory.createTitledBorder(null, "Formas Geometricas", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION));
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelMenuSuperior, gridBagConstraints);
		
		panelMenuSombreamento.setBorder(BorderFactory.createTitledBorder(null, "Sombreamento", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION));
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelMenuSombreamento, gridBagConstraints);
		
		panelDesenho.setBorder(BorderFactory.createTitledBorder(""));
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.weighty = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelDesenho, gridBagConstraints);
		
		panelMenuInferior.add(btnSobre);
		panelMenuInferior.add(btnSair);
		
		panelMenuInferior.setBorder(BorderFactory.createTitledBorder(null, "Menu", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION));
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 3;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelMenuInferior, gridBagConstraints);
		
		this.setExtendedState(MAXIMIZED_BOTH);	
		this.setVisible(true);
	}

	// Declaracao dos componentes da GUI
	private javax.swing.JPanel panelMenuSuperior;
	private javax.swing.JPanel panelMenuInferior;
	private PainelSombreamento panelMenuSombreamento;
	private PainelDesenho panelDesenho;
	private JButtonSair btnSair;
	private JButtonSobre btnSobre;
	private JButtonDesenhar btnDesenhar;
	private JButtonLimpar btnLimpar;
	private javax.swing.JComboBox cmbFormas;

	// Metodos getters e setters
	public PainelDesenho getPanelDesenho() {
		return panelDesenho;
	}

	public PainelSombreamento getPanelMenuSombreamento() {
		return panelMenuSombreamento;
	}

	public javax.swing.JComboBox getCmbFormas() {
		return cmbFormas;
	}

	public JButtonSair getBtnSair() {
		return btnSair;
	}

	public JButtonSobre getBtnSobre() {
		return btnSobre;
	}

	public JButtonDesenhar getBtnDesenhar() {
		return btnDesenhar;
	}

	public JButtonLimpar getBtnLimpar() {
		return btnLimpar;
	}
}
